﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Text;
using SystemHelper;

/// <summary>
/// Dining 的摘要说明
/// </summary>
public class Dining
{
	public Dining()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public DataSet GetDinner()
    {
        
        DataTable dt = null;
        DataSet ds = new DataSet();
        OleDbDataReader drclass = null;
        
        OledbHelper ohp = new OledbHelper();
        drclass = GetDinnerClass();
        if (drclass != null)
        {
            while (drclass.Read())
            {   StringBuilder sqlStr = new StringBuilder();
                OleDbDataReader dr = null;
                DataSet myds = new DataSet();
                sqlStr.Append(" SELECT ");
                sqlStr.Append(" DID, ");
                sqlStr.Append(" DName, ");
                sqlStr.Append(" DContent, ");
                sqlStr.Append(" DAddTime, ");
                sqlStr.Append(" DPrice, ");
                sqlStr.Append(" DClass, ");
                sqlStr.Append(" DPic ");
                sqlStr.Append(" FROM ");
                sqlStr.Append(" TB_Dinner ");
                sqlStr.Append(" where DClass=" + Convert.ToInt32(drclass["DCID"].ToString()));
                sqlStr.Append(" order by DAddTime desc");
                ohp.RunSQL(sqlStr.ToString(), out dr);
                
                if (dr != null)
                {               
                        dt = SystemTools.ConvertDataToDataTable(dr);
                        ds.Tables.Add(dt);
                }
            }
        }
        return ds;
    }

    public OleDbDataReader GetDinnerClass()
    {
        OleDbDataReader dr = null;
        StringBuilder sqlStr = new StringBuilder();
        sqlStr.Append(" SELECT ");
        sqlStr.Append(" DCID, ");
        sqlStr.Append(" DCNAME");
        sqlStr.Append(" from TB_DinnerClass ");
        sqlStr.Append(" order by DCID ");
        OledbHelper ohp = new OledbHelper();
        ohp.RunSQL(sqlStr.ToString(), out dr);
        return dr;
    }

    public int AddDinner(DinnerEles de)
    {
        if (de != null)
        {
            StringBuilder sqlStr = new StringBuilder();
            sqlStr.Append(" insert into TB_Dinner(");
            sqlStr.Append(" DName,");
            sqlStr.Append(" DContent, ");
            sqlStr.Append(" DPrice, ");
            sqlStr.Append(" DClass ,");
            sqlStr.Append(" DPic )");
            sqlStr.Append(" values('");
            sqlStr.Append(de.DinnerName+"','");
            sqlStr.Append(de.DinnerContent + "','");
            sqlStr.Append(de.DinnerPrice + "','");
            sqlStr.Append(de.DinnerClass + "','");
            sqlStr.Append(de.DinnerPicPath + "'");
            sqlStr.Append(" )");
            OledbHelper ohp = new OledbHelper();
            return ohp.RunSQL(sqlStr.ToString());
        }
        return 0;
    }
}
